package yxnote;

import java.io.IOException;

import yxnote.PMF;

import javax.jdo.PersistenceManager;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class CreateCategory extends HttpServlet {
    public void doPost(HttpServletRequest req, HttpServletResponse resp) throws IOException {
        PersistenceManager pm = PMF.get().getPersistenceManager();
        
        String name = req.getParameter("name");
        Category category = new Category(name);
        
        try {
            pm.makePersistent(category);
        } finally {
            pm.close();
        }
        
        resp.sendRedirect("/category/index.jsp");
    }
}
